//index.js
//获取应用实例
const wxapi = require('../../utils/wxapi.js');
const util = require('../../utils/util.js');
const app = getApp()

Page({
  data: { 
    motto: 'Hello World',
    userInfo: {},
    hasUserInfo: false,
    canIUse: wx.canIUse('button.open-type.getUserInfo'),
    noticeList:[]
  },
  //事件处理函数
  bindViewTap: function() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad: function () {
    // wx.getSetting
    // this.getNoticeList();  
  },
  onShow:function(){
    this.getNoticeList();
  },
  getUserInfo: function(e) {
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  enterNotice(e){
    wx.navigateTo({
      url: '/pages/notice/notice?id=' + e.currentTarget.dataset.id
    })
  },
  getNoticeList(){
    let that = this;
    wxapi.getNoticeList(wx.getStorageSync('secKey')).then(data => {
      let newData = data.data.map((item) =>{
        item.createtime = util.formatTime(new Date(item.createtime / 1000))
        return item;
      })
      that.setData({ noticeList: newData})
    }) 
  },
  searchInput(e){
    console.log(e);
    // wxapi.searchByWords(wx.getStorageSync('secKey'),e.detail.value).then(res=>{
    //   wx.navigateTo({
    //     url: '/pages/result/result',
    //   })
    // })
    let val = e.detail.value;
    if(val=="") return;
    wx.navigateTo({
      url: '/pages/query/query?keyword='+e.detail.value+'&type=search'
      ,
    })
  }
})
